package com.fdm.model.accounts;

import java.io.Serializable;
import java.util.Map;

import com.fdm.model.exceptions.BankManagerException;
import com.fdm.model.exceptions.InsufficientFundsException;
import com.fdm.model.exceptions.LessThanZeroException;

public class ConcreteAccount implements _Account, Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -471515619423215629L;
	private int accountNumber;
	private String accountType;
	private String name;
	private double balance;
		
	@Override
	public int getAccountNumber() {
		return accountNumber;
	}
	@Override
	public String getAccountType() {
		return accountType;
	}
	@Override
	public String getName() {
		return name;
	}
	@Override
	public double getBalance() {
		return balance;
	}
	@Override
	public double getOverDraftLimit() {
		return 0;
	}
	@Override
	public void withdraw(Double amount) 
			throws InsufficientFundsException, LessThanZeroException{
		if (amount >=0)
		{
			if (this.getBalance() - amount >=0)
			{
				this.setBalance(this.getBalance() - amount);
			}
			else
			{
				throw new InsufficientFundsException();
			}
		}
		else 
		{
			throw new LessThanZeroException();
		}
	}
	@Override
	public void deposit(Double amount) throws LessThanZeroException{
		if (amount >= 0)
		{
			this.setBalance(this.getBalance() + amount);
		}
		else
		{
			throw new LessThanZeroException();
		}
	}
	@Override
	public void setAccountNumber(Integer accountNumber) {
		if(accountNumber!=null)this.accountNumber = accountNumber;
	}
	@Override
	public void setAccountType(String accountType) {
		if(accountType!=null)this.accountType = accountType;
	}
	@Override
	public void setName(String name) {
		if(name!=null)this.name = name;
	}
	@Override
	public void setBalance(Double balance) throws LessThanZeroException {
		if(balance>=0){
			this.balance = balance;
		}
		else throw new LessThanZeroException();
	
	}

	@Override
	public void setAttributes(Map<String, Object> parameters) 
			throws BankManagerException{
		this.setAccountNumber( (Integer) parameters.get("accountNumber"));
		this.setAccountType( (String) parameters.get("accountType"));
		this.setName( (String) parameters.get("name"));
		this.setBalance( (Double) parameters.get("balance"));
	}
}
